﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace CentralMonitoring
{
    
    public partial class UserPwdEdit : Form
    {
        private string pwd = "";
        public UserPwdEdit()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxNewOK.Text) || string.IsNullOrEmpty(textBoxNew.Text))
            {
                MessageBox.Show("密码输入不能为空！", "提示");
                return;
            }
            if (textBoxOld.Text != pwd)
            {
                MessageBox.Show("原密码输入错误！","提示");
                return;
            }
            if (textBoxNew.Text != textBoxNewOK.Text)
            {
                MessageBox.Show("新密码输入不一致！", "提示");
                return;
            }
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            config.AppSettings.Settings["pwd"].Value = textBoxNew.Text;
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
            MessageBox.Show("操作成功！", "提示");
            this.DialogResult = DialogResult.OK;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void UserPwdEdit_Load(object sender, EventArgs e)
        {
            pwd = ConfigurationManager.AppSettings["pwd"].ToString();
        }
    }
}
